
package edu.uoc.tdp.client.proves;



import edu.uoc.tdp.beans.conexio.ResponsableEvents;
import edu.uoc.tdp.beans.proves.EstatProva;
import edu.uoc.tdp.beans.proves.Prova;
import edu.uoc.tdp.common.EOlympicsUtils;
import edu.uoc.tdp.common.RemotProvesInterface;
import edu.uoc.tdp.common.TDSLanguageUtils;
import java.rmi.RemoteException;
import java.util.List;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;

/**
 * Panell per tancar les competicions.  
 * @author Grup 5 1X4j
 */
public class PanelTancarProves extends javax.swing.JFrame {
    
    private RemotProvesInterface remotProves;
    private ResponsableEvents usuari;
    private List<Prova> proves;
    private Prova provaSeleccionada;
    /**
     * Constructor per defecte.
     */
    public PanelTancarProves() {
        initComponents();
        pintarEtiquetes();            
    }
    /**
     * Constructor amb un llistat de proves
     * @param proves            Llista de proves
     */
    public PanelTancarProves(List<Prova> proves){
        initComponents();
        pintarEtiquetes();
        borrarDades();
      
        this.proves=proves;
        carregarProves();
    }
    /**
     * Constructor amb dos paràmetres, es el que fa servir per via remot
     * @param pUsuari           usuari de la connexio
     * @param pRemotProves      Remot que ens permet realitzar la connexió amb el servidor
     */
    public PanelTancarProves( ResponsableEvents pUsuari,RemotProvesInterface pRemotProves){
        initComponents();
        pintarEtiquetes();
        borrarDades();
        this.remotProves=pRemotProves;
        this.usuari=pUsuari;
        try {
            proves=remotProves.getProvesPerTancar();            
            carregarProves();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);  
        }
    }
    /** 
     * Codi de generació automàtica NETBEANS
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPbotons = new javax.swing.JPanel();
        jBSortir = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTaulaProves = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        jBTancarComp = new javax.swing.JButton();
        jBCercarProves = new javax.swing.JButton();
        jTIniciRealitzacio = new javax.swing.JLabel();
        jTRonda = new javax.swing.JLabel();
        jTFiInscripcio = new javax.swing.JLabel();
        jLIniRealitzacio = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTFiRealitzacio = new javax.swing.JLabel();
        jLIniInscripcio = new javax.swing.JLabel();
        jLFiRealitzacio = new javax.swing.JLabel();
        jLFiInscripcio = new javax.swing.JLabel();
        jTIniciInscripcio = new javax.swing.JLabel();
        jLProva = new javax.swing.JLabel();
        jTIdProva = new javax.swing.JLabel();
        jPbotons1 = new javax.swing.JPanel();
        jLabelData = new javax.swing.JLabel();
        jLabelData1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        jBSortir.setFont(new java.awt.Font("Tahoma", 0, 10));
        jBSortir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/BotoSortir.png"))); // NOI18N
        jBSortir.setText("Sortir");
        jBSortir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jBSortir.setMaximumSize(new java.awt.Dimension(60, 60));
        jBSortir.setMinimumSize(new java.awt.Dimension(60, 60));
        jBSortir.setPreferredSize(new java.awt.Dimension(65, 60));
        jBSortir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jBSortir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBSortirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPbotonsLayout = new javax.swing.GroupLayout(jPbotons);
        jPbotons.setLayout(jPbotonsLayout);
        jPbotonsLayout.setHorizontalGroup(
            jPbotonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPbotonsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBSortir, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(55, Short.MAX_VALUE))
        );
        jPbotonsLayout.setVerticalGroup(
            jPbotonsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPbotonsLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBSortir, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTaulaProves.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Prova", "Tipus Ronda", "Estat"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTaulaProves.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTaulaProvesMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTaulaProves);

        jBTancarComp.setText("Tancar Competicio");
        jBTancarComp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBTancarCompActionPerformed(evt);
            }
        });

        jBCercarProves.setText("Tancar Competicio");
        jBCercarProves.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBCercarProvesActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(37, Short.MAX_VALUE)
                .addComponent(jBCercarProves, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(157, 157, 157)
                .addComponent(jBTancarComp, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(13, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBCercarProves, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jBTancarComp, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        jTIniciRealitzacio.setForeground(java.awt.Color.blue);
        jTIniciRealitzacio.setText(".");

        jTRonda.setForeground(java.awt.Color.blue);
        jTRonda.setText(".");

        jTFiInscripcio.setForeground(java.awt.Color.blue);
        jTFiInscripcio.setText(".");

        jLIniRealitzacio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLIniRealitzacio.setText("Inici Realització");

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Ronda:");

        jTFiRealitzacio.setForeground(java.awt.Color.blue);
        jTFiRealitzacio.setText(".");

        jLIniInscripcio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLIniInscripcio.setText("Inici Inscricpció:");

        jLFiRealitzacio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLFiRealitzacio.setText("Final Realització");

        jLFiInscripcio.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLFiInscripcio.setText("FinalInscripció:");

        jTIniciInscripcio.setForeground(java.awt.Color.blue);
        jTIniciInscripcio.setText(".");

        jLProva.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLProva.setText("Inici Inscricpció:");

        jTIdProva.setForeground(java.awt.Color.blue);
        jTIdProva.setText(".");

        jLabelData.setFont(new java.awt.Font("Tahoma", 2, 12)); // NOI18N
        jLabelData.setForeground(javax.swing.UIManager.getDefaults().getColor("PropSheet.selectedSetBackground"));
        jLabelData.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelData.setText("jLabel1");
        jLabelData.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        jLabelData1.setFont(new java.awt.Font("Tahoma", 2, 12)); // NOI18N
        jLabelData1.setForeground(javax.swing.UIManager.getDefaults().getColor("PropSheet.selectedSetBackground"));
        jLabelData1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabelData1.setText("Data Actual:");
        jLabelData1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

        javax.swing.GroupLayout jPbotons1Layout = new javax.swing.GroupLayout(jPbotons1);
        jPbotons1.setLayout(jPbotons1Layout);
        jPbotons1Layout.setHorizontalGroup(
            jPbotons1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPbotons1Layout.createSequentialGroup()
                .addContainerGap(56, Short.MAX_VALUE)
                .addComponent(jLabelData1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabelData, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPbotons1Layout.setVerticalGroup(
            jPbotons1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPbotons1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPbotons1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelData, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelData1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                        .addGap(15, 15, 15)
                                        .addComponent(jLProva, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLIniInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLFiInscripcio, javax.swing.GroupLayout.DEFAULT_SIZE, 122, Short.MAX_VALUE)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jTIniciInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTFiInscripcio, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTIdProva, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLFiRealitzacio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLIniRealitzacio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(16, 16, 16)
                                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(jTFiRealitzacio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jTIniciRealitzacio, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(jTRonda, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(45, 45, 45))))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGap(19, 19, 19)
                            .addComponent(jScrollPane1))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jPbotons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(121, 121, 121)
                            .addComponent(jPbotons1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPbotons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jPbotons1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLProva)
                            .addComponent(jTIdProva))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTIniciInscripcio)
                            .addComponent(jLIniInscripcio))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTFiInscripcio)
                            .addComponent(jLFiInscripcio)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLIniRealitzacio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLFiRealitzacio))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTRonda, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTIniciRealitzacio)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTFiRealitzacio)))
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
   /**
     * Acció de sortir 
     * @param evt           Disparador que executa aquesta acció
     */
    private void jBSortirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBSortirActionPerformed
        this.dispose();
    }//GEN-LAST:event_jBSortirActionPerformed
    /**
     * Acció de buscar proves   
     * @param evt           Disparador que executa aquesta acció
     */
    private void jBCercarProvesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBCercarProvesActionPerformed
      try{
            proves=remotProves.getProvesPerTancar();       
            borrarDades();
            carregarProves();            
        }catch (RemoteException re){
            JOptionPane.showMessageDialog(null,TDSLanguageUtils.getMessage("ERR_REMOT") , "ERR", JOptionPane.ERROR_MESSAGE);                                
        }catch (Exception e){
            if (e.getMessage()==null){
                JOptionPane.showMessageDialog(null,TDSLanguageUtils.getMessage("ERR_CONEXIO_DESC") , "ERR", JOptionPane.ERROR_MESSAGE);                                
            }else{
                JOptionPane.showMessageDialog(null, e.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);                                
            }
            
        }        
    }//GEN-LAST:event_jBCercarProvesActionPerformed
    /**
     * Acció Tancar una competició
     * @param evt           Disparador que executa aquesta acció
     */
    private void jBTancarCompActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBTancarCompActionPerformed
        String msg="";
        String tipusRonda="";
        EstatProva tempEstat=null;
        if(provaSeleccionada.getRondaEliminatoria()!=null ){
            msg= TDSLanguageUtils.getMessage("proves.pantalla.tancar.confirmacio.eliminatoria")+" "+provaSeleccionada.getDescripcio()+"?" ;
            tempEstat=EstatProva.CLASSIFICACIOPREVIA;
            tipusRonda="E";
        }else if (provaSeleccionada.getRondaFinal()!=null){
            msg= TDSLanguageUtils.getMessage("proves.pantalla.tancar.confirmacio.final")+" "+provaSeleccionada.getDescripcio()+"?" ;
            tempEstat=EstatProva.CLASSIFICACIOFINAL;
            tipusRonda="F";                        
        }                             
        if( JOptionPane.showConfirmDialog                           
                        (null, msg, 
                        TDSLanguageUtils.getMessage("proves.pantalla.tancar.confirmacio.tancarProva"), JOptionPane.OK_CANCEL_OPTION)==0){                   
                provaSeleccionada.setEstat(tempEstat);
                try {
                    provaSeleccionada.setUsuariModificacio(usuari);
                    remotProves.tancarParticipacio(provaSeleccionada, tipusRonda);                    
                    if(tipusRonda.equals("E")){                        
                        remotProves.inscriureAFinal(provaSeleccionada,tipusRonda);                        
                        JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("proves.pantalla.tancar.confirmacio.paneltancarproves") + " " +provaSeleccionada.getEstat() +"\n" + TDSLanguageUtils.getMessage("proves.pantalla.tancar.confirmacio.paneltancarproveseliminatoria"), TDSLanguageUtils.getMessage("proves.pantalla.manteniment.optionmessage.confirmacio"), JOptionPane.INFORMATION_MESSAGE);                                                                   
                    }else{
                        JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("proves.pantalla.tancar.confirmacio.paneltancarproves") + " " +provaSeleccionada.getEstat(), TDSLanguageUtils.getMessage("proves.pantalla.manteniment.optionmessage.confirmacio"), JOptionPane.INFORMATION_MESSAGE);                                                                   
                    }                                            
                    borrarDades();
                    proves=remotProves.getProvesPerTancar();
                    carregarProves();            
                }catch (RemoteException re){
                        JOptionPane.showMessageDialog(null,TDSLanguageUtils.getMessage("ERR_REMOT") , "ERR", JOptionPane.ERROR_MESSAGE);                                
                }catch (Exception e) {
                     JOptionPane.showMessageDialog(null, e.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);                                
                }
        
        }
    }//GEN-LAST:event_jBTancarCompActionPerformed
    /**
     * Acció de seleccionar una prova
     * @param evt               Disparador
     */
    private void jTaulaProvesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTaulaProvesMousePressed
        if(jTaulaProves.getSelectedRow()>=0){
            provaSeleccionada=proves.get(jTaulaProves.getSelectedRow()); 
            jTIdProva.setText(provaSeleccionada.getIdProva().toString());
            jTIniciInscripcio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getDataIniInscripcio()));
            jTFiInscripcio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getDataFiInscripcio()));
            if(provaSeleccionada.getRondaEliminatoria()!=null){
                jTRonda.setText("ELIMINATORIA");
                jTIniciRealitzacio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getRondaEliminatoria().getDataIniRealitzacio()));
                jTFiRealitzacio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getRondaEliminatoria().getDataFiRealitzacio()));
            }else{
                jTRonda.setText("FINAL");
                jTIniciRealitzacio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getRondaFinal().getDataIniRealitzacio()));
                jTFiRealitzacio.setText(EOlympicsUtils.getStringDate(provaSeleccionada.getRondaFinal().getDataFiRealitzacio()));
            }
            jBTancarComp.setEnabled(true);
        }
    }//GEN-LAST:event_jTaulaProvesMousePressed

    /**
     * Presenta les proves a la taula de la finestra. Carrega les dades obtingudes del servidor
     */
    private void carregarProves(){        
            try {   
                jLabelData.setText(EOlympicsUtils.getStringDate(new java.util.Date())); 
                jTaulaProves.setModel(carregarTaula(proves));               
                TableColumnModel modelColumna = jTaulaProves.getColumnModel();         
                modelColumna.getColumn(0).setPreferredWidth(250);
                modelColumna.getColumn(2).setPreferredWidth(150);
                if(proves.isEmpty()){
                    JOptionPane.showMessageDialog(null, TDSLanguageUtils.getMessage("proves.pantalla.tancar.noelements.panel"), TDSLanguageUtils.getMessage("proves.pantalla.manteniment.optionmessage.confirmacio"), JOptionPane.INFORMATION_MESSAGE);                                                                   
                }
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(null, ex.getMessage(), "ERR", JOptionPane.ERROR_MESSAGE);                                
            }
         
    }
    /**
     * Carrega el model de la taula
     * @param proves            dades a carregar
     * @return 
     */
    private DefaultTableModel carregarTaula(List<Prova> proves){
        String [] columnes={"PROVA","TIPUS RONDA","ESTAT"};        
        Object[][] dades=new Object[proves.size()][3];                          
        Integer i=0;
        DefaultTableModel dadesTaula;
          for(Prova p:proves){
            dades[i][0]=p.getDescripcio();
            dades[i][2]=p.getEstat();
            if(p.getEstat().equals(EstatProva.COMPETICIOPREVIA.getEstat())){
                dades[i][1]="ELIMINATORIA";
            }
            else if (p.getEstat().equals(EstatProva.COMPETICIOFINAL.getEstat())){
                dades[i][1]="FINAL";
            }else{
                dades[i][1]="-";
            }
            
            i++;
        }        
        dadesTaula=new DefaultTableModel(dades,columnes)
                 {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            @Override
            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        };
        
        
        
        return dadesTaula;        
    }    
    /**
     * Personalitza les etiquetes de la pantalla
     */
    private void pintarEtiquetes(){        
        this.setTitle(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settitol.paneltancar"));
        jBSortir.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.tooltip.jBSortir"));
        jBSortir.setText(TDSLanguageUtils.getMessage("proves.pantalla.buscador.settext.sortir"));
        jBTancarComp.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.tooltip.jBTancarComp"));
        jBTancarComp.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jBTancarComp"));
        jBCercarProves.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jBCercarProves"));
        jBCercarProves.setToolTipText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.tooltip.jBCercarProves"));
        
        
        jLFiInscripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLFiInscripcio"));
        jLFiRealitzacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLFiRealitzacio"));
        jLIniInscripcio.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLIniInscripcio"));
        jLIniRealitzacio.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLIniRealitzacio"));
        jLProva.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLProva"));
        jLabel8.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLRonda"));
        jLabelData1.setText(TDSLanguageUtils.getMessage("proves.pantalla.tancar.settext.jLabelData1"));
    }
    /**
     * Neteja la pantalla de dades
     */
     private void borrarDades(){        
        jTIdProva.setText("");
        jTFiInscripcio.setText("");
        jTFiRealitzacio.setText("");
        jTIniciInscripcio.setText("");
        jTIniciRealitzacio.setText("");
        jTRonda.setText("");
        jBTancarComp.setEnabled(false);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCercarProves;
    private javax.swing.JButton jBSortir;
    private javax.swing.JButton jBTancarComp;
    private javax.swing.JLabel jLFiInscripcio;
    private javax.swing.JLabel jLFiRealitzacio;
    private javax.swing.JLabel jLIniInscripcio;
    private javax.swing.JLabel jLIniRealitzacio;
    private javax.swing.JLabel jLProva;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabelData;
    private javax.swing.JLabel jLabelData1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPbotons;
    private javax.swing.JPanel jPbotons1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jTFiInscripcio;
    private javax.swing.JLabel jTFiRealitzacio;
    private javax.swing.JLabel jTIdProva;
    private javax.swing.JLabel jTIniciInscripcio;
    private javax.swing.JLabel jTIniciRealitzacio;
    private javax.swing.JLabel jTRonda;
    private javax.swing.JTable jTaulaProves;
    // End of variables declaration//GEN-END:variables
}
